import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp

/**
 * @author ldh
 * 时间: 2022/10/13 16:43
 * 邮箱: 2637614077@qq.com
 */

private val outputText = mutableStateOf("")

private val inputText = mutableStateOf("")

@Composable
fun TransformScreen() {
    Column(modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) {
        TextField(
            modifier = Modifier.fillMaxWidth().defaultMinSize(minHeight = 100.dp).padding(horizontal = 20.dp),
            value = inputText.value,
            onValueChange = {
                inputText.value = it
            })

        Spacer(modifier = Modifier.height(20.dp))

        Row {
            for (i in 1 until PAGE_TITLES.size) {
                Spacer(modifier = Modifier.width(3.dp))
                Button(onClick = {
                    outputText.value = Transformer.transform(inputText.value)
                }) {
                    Text(text = PAGE_TITLES[i])
                }
                Spacer(modifier = Modifier.width(3.dp))
            }
        }

        Box(contentAlignment = Alignment.Center, modifier = Modifier.padding(vertical = 50.dp, horizontal = 20.dp)) {
            Box(
                modifier = Modifier.fillMaxSize()
                    .background(
                        brush = Brush.horizontalGradient(listOf(Color.Gray, Color.Gray)),
                        alpha = 0.15f,
                        shape = RoundedCornerShape(10.dp)
                    )
                    .alpha(0.5f)
            )
            LazyColumn {
                item {
                    SelectionContainer {
                        Text(text = outputText.value, modifier = Modifier.fillMaxSize(), textAlign = TextAlign.Center)
                    }
                }
            }
        }
    }
}